const path = require('path')
//yarn add html-webpack-plugin --dev 自动生成HTML插件
const HtmlWebpackPlugin = require('html-webpack-plugin')
//插件加载
const { VueLoaderPlugin } = require('vue-loader')

module.exports = {
    //打包入口文件
    entry: path.join(__dirname,'./src/main.js'),
    output: {
        //打包输出路径
        path: path.join(__dirname,'./dist'),
        //输出，
        filename: '[name].[hash:6].js'
    },
    //配置项通过别名来把原导入路径映射成一个新的导入路径
    resolve: {
        //在导入语句没带文件后缀时，Webpack 会自动带上后缀后去尝试访问文件是否存在
        extensions: ['.js', '.vue', '.json'],//用于配置在尝试过程中用到的后缀列表
        alias: {
            '@':path.join(__dirname,'src')
        }
    },
    module: {
        rules: [
            {
                test: /\.less?$/,
                use: [
                    'vue-style-loader',
                    'css-loader',
                    'less-loader'
                ]
            }, 
            {
                test: /\.vue$/,
                use: 'vue-loader'
            }, 
            {
                test: /\.js$/,
                exclude: /node_modules/,//编译时去除node_modeuls中的内容
                use: {
                    loader: 'babel-loader'
                }
            }, 
            {
                test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
                use: {
                    loader: 'url-loader',
                    options: {
                        limit: 10 * 1024,
                        esModule: false,
                    }
                }
            }, 
            {
                test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
                use: {
                    loader: 'url-loader',
                    options: {
                        limit: 10000,
                    }
                }
            }, {
                test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
                use: {
                    loader: 'url-loader',
                    options: {
                        limit: 10000,
                    }
                }
            }
        ]
    },

    plugins: [
        //自动生成HTML插件
        new HtmlWebpackPlugin({
            template: 'public/index.html',
            options:{
                title:"vue-app"
            }
        }),
        new VueLoaderPlugin()
    ]
}